﻿package plugin.accomplishment
{
    import com.core.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.accomplishment.consts.*;
    import pluginfw.nio.*;
    import uiresource.Accomplishment.*;
    import view.light.*;
    import view.mornExtends.*;
    import vo.*;

    public class XunzhangUICON extends XunzhangUI
    {
        private var cfgxz:Object;
        private var severid:int = 0;
        private var _data:Object;
        private var _cfgdh:Object;
        private var _cfgitem:Object;
        private var _cfgAch:Object;
        private var chengJarr:Array;
        public var xunzhang:Class;
        public var xzMC:XMLMovieClip;
        private var successMc:XMLMovieClip;
        private var _mask:Sprite;
        private var itemarr:Array;
        private var showArr:Array;
        public static const guanweiEffect:Class = XunzhangUICON_guanweiEffect;

        public function XunzhangUICON()
        {
            this.xunzhang = XunzhangUICON_xunzhang;
            this.showArr = ["物理攻击", "魔法攻击", "道士攻击", "法防", "物防"];
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            PluginManager.instance.sendToBufferServer("achievement", CMDAchievement.XunZhang, new Output());
            this._mask = new Sprite();
            this._mask.graphics.beginFill(1048575, 1);
            this._mask.graphics.drawRect(0, 0, 346, 15);
            this._mask.graphics.endFill();
            var _loc_1:* = view_xz.getChildIndex(jindu);
            view_xz.addChildAt(this._mask, (_loc_1 + 1));
            jindu.mask = this._mask;
            this._mask.x = jindu.x;
            this._mask.y = jindu.y;
            this.getValue();
            this.addlistener();
            return;
        }// end function

        public function initLoad() : void
        {
            if (this.successMc == null)
            {
                App.mloader3.loadSWF(Config.getUrl("assets/images/mainui/guanwei.swf"), 1, new Handler(this.mcLoaded));
            }
            return;
        }// end function

        private function mcLoaded(param1) : void
        {
            var _loc_2:* = new XML(new guanweiEffect());
            this.successMc = new XMLMovieClip("guanwei", _loc_2);
            this.successMc.mouseChildren = false;
            this.successMc.interval = 165;
            this.successMc.mouseEnabled = false;
            this.successMc.x = -20;
            this.successMc.y = -150;
            this.successMc.visible = false;
            this.successMc.play();
            view_xz.addChild(this.successMc);
            return;
        }// end function

        private function getValue() : void
        {
            var _loc_1:Object = null;
            if (!this._cfgAch)
            {
                this._cfgAch = ConfigDictionary.data.achievement;
            }
            if (!this._cfgdh)
            {
                this._cfgdh = ConfigDictionary.data.acmdh;
            }
            if (!this._cfgitem)
            {
                this._cfgitem = ConfigDictionary.data.item;
            }
            this.chengJarr = [];
            for each (_loc_1 in this._cfgAch)
            {
                
                if (_loc_1.fenlei >= 1 && _loc_1.title > 1000)
                {
                    this.chengJarr.push(_loc_1);
                }
            }
            this.chengJarr.sortOn("id", Array.NUMERIC);
            return;
        }// end function

        public function GetXunZdh(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            if (param1)
            {
                this.itemarr = param1.medals;
                _loc_2 = this.itemarr.length;
                this.severid = _loc_2 + 1;
                if (_loc_2 <= 0)
                {
                    _loc_3 = this._cfgdh[1].itemid;
                    this.showProperty(this.severid);
                    _loc_5 = this._cfgitem[_loc_3];
                    _loc_4 = null;
                }
                else if (_loc_2 > 0 && _loc_2 < 10)
                {
                    _loc_3 = this._cfgdh[(_loc_2 + 1)].itemid;
                    this.showProperty(this.severid);
                    _loc_5 = this._cfgitem[_loc_3];
                    _loc_4 = this._cfgitem[this._cfgdh[_loc_2].itemid];
                }
                else
                {
                    _loc_3 = this._cfgdh[_loc_2].itemid;
                    this.showProperty(_loc_2);
                    _loc_5 = null;
                    _loc_4 = this._cfgitem[this._cfgdh[_loc_2].itemid];
                }
                ts_item.effshow = true;
                ts_item.data = _loc_5;
                this.initPropertyList(_loc_4, _loc_5);
            }
            this.initshow();
            return;
        }// end function

        public function upDateXZ() : void
        {
            if (this.severid <= 10)
            {
                this.showProperty(this.severid);
            }
            return;
        }// end function

        private function initshow() : void
        {
            var _loc_4:Object = null;
            var _loc_1:Array = [];
            var _loc_2:Array = [];
            var _loc_3:int = 1;
            while (_loc_3 <= 10)
            {
                
                _loc_4 = ItemObject.create(this._cfgitem[this._cfgdh[_loc_3].itemid]);
                if (_loc_4)
                {
                    _loc_2.push(_loc_4);
                }
                _loc_3++;
            }
            list1.array = _loc_2;
            list1.renderHandler = new Handler(this.listHandler1);
            return;
        }// end function

        private function listHandler1(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:FlashItem = null;
            var _loc_5:Label = null;
            var _loc_6:Label = null;
            if (param2 < list1.array.length)
            {
                _loc_3 = list1.array[param2];
                _loc_4 = param1.getChildByName("fi") as FlashItem;
                _loc_4.effshow = true;
                _loc_4.data = _loc_3;
                _loc_5 = param1.getChildByName("item_name") as Label;
                _loc_5.text = _loc_3.name;
                _loc_6 = param1.getChildByName("label_huode") as Label;
                if (this.itemarr[param2])
                {
                    _loc_6.color = 5485622;
                    _loc_6.text = "(已获得)";
                }
                else
                {
                    _loc_6.color = 13051156;
                    _loc_6.text = "(未获得)";
                }
            }
            return;
        }// end function

        private function addlistener() : void
        {
            btn_dhxz.addEventListener(MouseEvent.CLICK, this.onduihui);
            label_shuom.addEventListener(MouseEvent.ROLL_OVER, this.overLabel);
            label_shuom.addEventListener(MouseEvent.ROLL_OUT, this.outLabel);
            return;
        }// end function

        protected function outLabel(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function overLabel(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "1.完成成就分项，成就点数达到一定数量可兑换勋章，勋章增加大量属性。\n2.成就点数可以通过完成成就获得。\n3.兑换勋章时需要佩戴前一阶勋章在身上，兑换成功后身上勋章自动替换成下一阶。");
            return;
        }// end function

        private function initPropertyList(param1:Object, param2:Object = null) : void
        {
            var _loc_3:Array = [];
            var _loc_4:Array = [];
            if (param1)
            {
                _loc_3.push(param1.magicAtt + " - " + param1.magicAttMax);
                _loc_3.push(param1.phyAtt + " - " + param1.phyAttMax);
                _loc_3.push(param1.taoAtt + " - " + param1.taoAttMax);
                if (param1.phyDef != 0 && param1.phyDefMax != 0)
                {
                    param1.push(param1.phyDef + " - " + param1.phyDefMax);
                }
                if (param1.magicDef != 0 && param1.magicDefMax != 0)
                {
                    _loc_3.push(param1.magicDef + " - " + param1.magicDefMax);
                }
            }
            else
            {
                _loc_3 = [0, 0, 0];
            }
            if (param2)
            {
                _loc_4.push(param2.magicAtt + " - " + param2.magicAttMax);
                _loc_4.push(param2.phyAtt + " - " + param2.phyAttMax);
                _loc_4.push(param2.taoAtt + " - " + param2.taoAttMax);
                if (param2.phyDef != 0 && param2.phyDefMax != 0)
                {
                    _loc_4.push(param2.phyDef + " - " + param2.phyDefMax);
                }
                if (param2.magicDef != 0 && param2.magicDefMax != 0)
                {
                    _loc_4.push(param2.magicDef + " - " + param2.magicDefMax);
                }
            }
            else
            {
                _loc_4 = [0, 0, 0];
            }
            propertyList1.array = _loc_4;
            propertyList1.renderHandler = new Handler(this.propertyListHandler1);
            propertyList.array = _loc_3;
            propertyList.renderHandler = new Handler(this.propertyListHandler);
            return;
        }// end function

        private function propertyListHandler1(param1:Component, param2:int) : void
        {
            var _loc_3:Label = null;
            var _loc_4:Label = null;
            if (param2 < propertyList1.array.length)
            {
                _loc_3 = param1.getChildByName("name_shuxing") as Label;
                _loc_3.text = this.showArr[param2] + "：";
                _loc_4 = param1.getChildByName("txt1") as Label;
                _loc_4.text = propertyList1.array[param2] + "";
            }
            return;
        }// end function

        private function propertyListHandler(param1:Component, param2:int) : void
        {
            var _loc_3:Label = null;
            var _loc_4:Label = null;
            if (param2 < propertyList.array.length)
            {
                _loc_3 = param1.getChildByName("name_shuxing") as Label;
                _loc_3.text = this.showArr[param2] + "：";
                _loc_4 = param1.getChildByName("txt1") as Label;
                _loc_4.text = propertyList.array[param2] + "";
            }
            return;
        }// end function

        protected function onduihui(event:MouseEvent) : void
        {
            var _loc_2:Output = null;
            var _loc_3:Array = null;
            var _loc_4:Output = null;
            if (this.severid)
            {
                if (this._data.res >= int(this._cfgdh[this.severid].cost))
                {
                    if (this.chengJarr[(this.severid - 1)].fenlei == 1)
                    {
                        if (this._data["t" + this._cfgdh[this.severid].needtitle] && int(this._data["t" + this._cfgdh[this.severid].needtitle]) == 1)
                        {
                            _loc_2 = new Output();
                            _loc_2.writeVarInt(this.severid, false);
                            PluginManager.instance.sendToBufferServer("achievement", CMDAchievement.SetdH, _loc_2);
                            this.showSuccess();
                        }
                        else
                        {
                            WarningManager.show(75);
                        }
                    }
                    else if (this.chengJarr[(this.severid - 1)].fenlei == 2)
                    {
                        _loc_3 = this._data["a" + this.chengJarr[(this.severid - 1)].id];
                        if (_loc_3 && _loc_3[1] >= 1)
                        {
                            _loc_4 = new Output();
                            _loc_4.writeVarInt(this.severid, false);
                            PluginManager.instance.sendToBufferServer("achievement", CMDAchievement.SetdH, _loc_4);
                            this.showSuccess();
                        }
                        else
                        {
                            WarningManager.show(75);
                        }
                    }
                }
                else
                {
                    WarningManager.show(74);
                }
            }
            return;
        }// end function

        private function showProperty(param1:int) : void
        {
            var _loc_4:Object = null;
            var _loc_5:Array = null;
            this._data = ModelProxy.getValue("data", "achievement");
            this.severid = param1;
            var _loc_2:int = 0;
            var _loc_3:Boolean = false;
            if (this._cfgdh[param1])
            {
                if (param1 == 1)
                {
                    label_mubiao1.text = "";
                }
                else
                {
                    _loc_4 = ItemObject.create(this._cfgitem[this._cfgdh[(param1 - 1)].itemid]);
                    if (this.inUser(this._cfgdh[(param1 - 1)].itemid))
                    {
                        label_mubiao1.text = "<font color=\'#B8764A\'>身上佩戴：" + _loc_4.name + "</font><font color=\'#009900\'>(已达成)</font>";
                    }
                    else
                    {
                        label_mubiao1.text = "<font color=\'#B8764A\'>身上佩戴：" + _loc_4.name + "</font><font color=\'#C72541\'>(未达成)</font>";
                    }
                }
                if (this.chengJarr[(param1 - 1)].fenlei == 1)
                {
                    if (this._data["t" + this._cfgdh[param1].needtitle] && int(this._data["t" + this._cfgdh[param1].needtitle]) == 1)
                    {
                        label_mubiao.text = "完成成就：" + this.chengJarr[(param1 - 1)].name + "<font color=\'#009900\'>(已达成)</font>";
                    }
                    else
                    {
                        label_mubiao.text = "完成成就：" + this.chengJarr[(param1 - 1)].name + "<font color=\'#C72541\'>(未达成)</font>";
                    }
                }
                else if (this.chengJarr[(param1 - 1)].fenlei == 2)
                {
                    _loc_5 = this._data["a" + this.chengJarr[(param1 - 1)].id];
                    if (_loc_5 && _loc_5[1] >= 1)
                    {
                        _loc_3 = true;
                        label_mubiao.text = "完成成就：" + this.chengJarr[(param1 - 1)].desc + "<font color=\'#009900\'>(已达成)</font>";
                    }
                    else
                    {
                        label_mubiao.text = "完成成就：" + this.chengJarr[(param1 - 1)].desc + "<font color=\'#C72541\'>(未达成)</font>";
                    }
                }
                this._mask.width = this._data.res / int(this._cfgdh[param1].cost) >= 1 ? (346) : (this._data.res / int(this._cfgdh[param1].cost) * 346);
                label_jindu.text = "成就点：" + this._data.res + "/" + int(this._cfgdh[param1].cost);
            }
            if ((this._data.res >= int(this._cfgdh[param1].cost) && this._data["t" + this._cfgdh[param1].needtitle] && int(this._data["t" + this._cfgdh[param1].needtitle]) == 1 || _loc_3) && btn_dhxz.label == "兑换勋章")
            {
                LightFactory.showlight(btn_dhxz);
            }
            else
            {
                LightFactory.clearlight(btn_dhxz);
            }
            return;
        }// end function

        private function inUser(param1:int) : Boolean
        {
            var _loc_2:* = ModelProxy.getValue("data", "arms");
            if (_loc_2[14] && _loc_2[14].itemid == param1)
            {
                return true;
            }
            return false;
        }// end function

        private function showSuccess() : void
        {
            this.successMc.visible = true;
            this.successMc.playFromTo(-1, (this.successMc.totalFrame - 1), new Handler(this.doEnd1));
            return;
        }// end function

        private function doEnd1() : void
        {
            this.successMc.visible = false;
            this.successMc.stop();
            return;
        }// end function

        public function clearMc() : void
        {
            if (this.successMc)
            {
                if (this.successMc.parent)
                {
                    this.successMc.dispose();
                    this.successMc.parent.removeChild(this.successMc);
                    this.successMc = null;
                }
            }
            return;
        }// end function

    }
}
